package com.chatify.app;


import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ChatListAdapter extends BaseAdapter {
  private final Context context;
  
  private List<ChatItem> chatItem;
  public ChatListAdapter(Context context, List<ChatItem> chatItem) {
	
    this.context = context;
    this.chatItem = chatItem;
  }

  public View getView(int position, View convertView, ViewGroup parent) {
	  if (convertView == null) {
	        // This a new view we inflate the new layout
	        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        convertView = inflater.inflate(R.layout.chat_row, parent, false);
	    }
    
    TextView sendermessage = (TextView) convertView.findViewById(R.id.sendermessage);
    TextView receivermessage = (TextView) convertView.findViewById(R.id.receivermessage);
    ChatItem item = chatItem.get(position);
    sendermessage.setText(item.sendermessage);
    receivermessage.setText(item.receivermessage);
    if(item.sendermessage.isEmpty())
    {
    
    	sendermessage.setVisibility(View.GONE);
    }
    
    if(item.receivermessage.isEmpty())
    {
    	receivermessage.setVisibility(View.GONE);
    
    }
    return convertView;
  }

public int getCount() {
    return chatItem.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}
} 